package com.example.server.controller;

import com.example.server.entity.Cart;
import com.example.server.entity.Product;
import com.example.server.entity.User;
import com.example.server.service.CartService;
import com.example.server.util.Util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("cart")
public class CartController extends BaseController{

    private final CartService cartService;

    public CartController(CartService cartService) {
        this.cartService = cartService;
    }

    @PostMapping("create")
    @ResponseBody
    private boolean create(@RequestBody Cart cart){
        cartService.create(cart);
        return true;
    }

    @GetMapping("queryByUid")
    @ResponseBody
    private List<Cart> queryByUid(@RequestParam BigInteger uid){
          List<Cart> list = cartService.queryList("queryByUid",uid);
          return list;
    }
    @GetMapping("queryById")
    @ResponseBody
    private Cart queryById(@RequestParam BigInteger cartid){
        Cart cart = cartService.queryOne("queryById",cartid);
        System.out.println(cart);
        return cart;

    }
    @PutMapping("modify")
    @ResponseBody
    private boolean modify(@RequestBody Cart cart){
        cartService.modify(cart);
        return true;
    }

    @DeleteMapping("removeById")
    @ResponseBody
    private boolean removeById(@RequestBody Map<String,BigInteger> map){
        BigInteger cartid = map.get("cartid");
        cartService.removeById(cartid);
        return true;
    }
}
